/*******************************************************************************
 * Copyright (c) 2006 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package mtbldomain.presentation.importwizard;

import java.util.List;

import mtbldomain.presentationmodel.importwizard.ImportWizardPresentationModel;
import mtblreader.ProjectDetail;

import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.ui.IImportWizard;
import org.eclipse.ui.IWorkbench;

import domain.presentation.chartview.MetricLineChartView;
import domain.presentation.metricview.MetricView;

public class ImportWizard extends Wizard implements IImportWizard {

	private ImportFilesWizardPage importFilesWizardPage;
	private ImportWizardPresentationModel importWizardPresentationModel = new ImportWizardPresentationModel();
	
	MetricView sampleView = new MetricView();
	MetricLineChartView metricLineChartView = new MetricLineChartView();

	public ImportWizard() {
		super();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jface.wizard.Wizard#performFinish()
	 */
	public boolean performFinish() {
		
		List<ProjectDetail> projectDetailList = importFilesWizardPage.getImportFilePresentationModel().getProjectDetailList();
		boolean answer = importWizardPresentationModel.convertProjectDetailList(projectDetailList);
		
		if(answer){
			sampleView.openMetricView();
			metricLineChartView.openLineChartView();
			return true;
		}
		return false;

		
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench,
	 * org.eclipse.jface.viewers.IStructuredSelection)
	 */
	public void init(IWorkbench workbench, IStructuredSelection selection) {
		setWindowTitle("File Import Wizard"); // NON-NLS-1
		setNeedsProgressMonitor(true);
		importFilesWizardPage = new ImportFilesWizardPage();

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jface.wizard.IWizard#addPages()
	 */
	public void addPages() {
		addPage(importFilesWizardPage);

	}

}
